<template>
  <div class="system-management">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <h1 class="page-title">系统管理</h1>
        <p class="page-subtitle">系统配置、日志管理和数据维护</p>
      </div>
      <div class="header-actions">
        <el-button type="primary" @click="refreshSystemInfo">
          <el-icon><Refresh /></el-icon>
          刷新状态
        </el-button>
      </div>
    </div>

    <!-- 系统状态概览 -->
    <el-row :gutter="20" class="status-row">
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="status-card">
          <div class="status-content">
            <div class="status-info">
              <div class="status-title">服务器状态</div>
              <div class="status-value" :class="systemStatus.server.status">
                {{ systemStatus.server.status === 'online' ? '正常' : '异常' }}
              </div>
            </div>
            <el-icon class="status-icon" :class="systemStatus.server.status">
              <Monitor />
            </el-icon>
          </div>
          <div class="status-details">
            <div class="detail-item">
              <span>CPU使用率:</span>
              <span>{{ systemStatus.server.cpu }}%</span>
            </div>
            <div class="detail-item">
              <span>内存使用率:</span>
              <span>{{ systemStatus.server.memory }}%</span>
            </div>
            <div class="detail-item">
              <span>运行时间:</span>
              <span>{{ systemStatus.server.uptime }}</span>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="status-card">
          <div class="status-content">
            <div class="status-info">
              <div class="status-title">数据库状态</div>
              <div class="status-value" :class="systemStatus.database.status">
                {{ systemStatus.database.status === 'online' ? '正常' : '异常' }}
              </div>
            </div>
            <el-icon class="status-icon" :class="systemStatus.database.status">
              <Coin />
            </el-icon>
          </div>
          <div class="status-details">
            <div class="detail-item">
              <span>连接数:</span>
              <span>{{ systemStatus.database.connections }}</span>
            </div>
            <div class="detail-item">
              <span>查询/秒:</span>
              <span>{{ systemStatus.database.qps }}</span>
            </div>
            <div class="detail-item">
              <span>存储使用:</span>
              <span>{{ systemStatus.database.storage }}</span>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="status-card">
          <div class="status-content">
            <div class="status-info">
              <div class="status-title">缓存状态</div>
              <div class="status-value" :class="systemStatus.cache.status">
                {{ systemStatus.cache.status === 'online' ? '正常' : '异常' }}
              </div>
            </div>
            <el-icon class="status-icon" :class="systemStatus.cache.status">
              <Lightning />
            </el-icon>
          </div>
          <div class="status-details">
            <div class="detail-item">
              <span>命中率:</span>
              <span>{{ systemStatus.cache.hitRate }}%</span>
            </div>
            <div class="detail-item">
              <span>内存使用:</span>
              <span>{{ systemStatus.cache.memory }}</span>
            </div>
            <div class="detail-item">
              <span>键数量:</span>
              <span>{{ systemStatus.cache.keys }}</span>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="status-card">
          <div class="status-content">
            <div class="status-info">
              <div class="status-title">存储状态</div>
              <div class="status-value" :class="systemStatus.storage.status">
                {{ systemStatus.storage.status === 'online' ? '正常' : '异常' }}
              </div>
            </div>
            <el-icon class="status-icon" :class="systemStatus.storage.status">
              <FolderOpened />
            </el-icon>
          </div>
          <div class="status-details">
            <div class="detail-item">
              <span>总容量:</span>
              <span>{{ systemStatus.storage.total }}</span>
            </div>
            <div class="detail-item">
              <span>已使用:</span>
              <span>{{ systemStatus.storage.used }}</span>
            </div>
            <div class="detail-item">
              <span>可用空间:</span>
              <span>{{ systemStatus.storage.free }}</span>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 功能模块 -->
    <el-row :gutter="20">
      <!-- 系统配置 -->
      <el-col :xs="24" :lg="12">
        <el-card class="module-card">
          <template #header>
            <div class="card-header">
              <span>系统配置</span>
              <el-button type="text" @click="loadSystemConfig">
                <el-icon><Refresh /></el-icon>
              </el-button>
            </div>
          </template>
          
          <el-form :model="systemConfig" label-width="120px">
            <el-form-item label="系统名称">
              <el-input v-model="systemConfig.systemName" />
            </el-form-item>
            
            <el-form-item label="系统描述">
              <el-input v-model="systemConfig.systemDescription" type="textarea" :rows="2" />
            </el-form-item>
            
            <el-form-item label="允许注册">
              <el-switch v-model="systemConfig.allowRegistration" />
            </el-form-item>
            
            <el-form-item label="邮件验证">
              <el-switch v-model="systemConfig.requireEmailVerification" />
            </el-form-item>
            
            <el-form-item label="最大文件大小">
              <el-input v-model="systemConfig.maxFileSize" placeholder="MB">
                <template #append>MB</template>
              </el-input>
            </el-form-item>
            
            <el-form-item label="会话超时">
              <el-input v-model="systemConfig.sessionTimeout" placeholder="分钟">
                <template #append>分钟</template>
              </el-input>
            </el-form-item>
            
            <el-form-item>
              <el-button type="primary" @click="saveSystemConfig" :loading="savingConfig">
                保存配置
              </el-button>
              <el-button @click="loadSystemConfig">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
      
      <!-- 系统日志 -->
      <el-col :xs="24" :lg="12">
        <el-card class="module-card">
          <template #header>
            <div class="card-header">
              <span>系统日志</span>
              <div class="header-actions">
                <el-button type="text" size="small" @click="clearLogs">
                  清空日志
                </el-button>
                <el-button type="text" size="small" @click="exportLogs">
                  导出日志
                </el-button>
                <el-button type="text" @click="loadSystemLogs">
                  <el-icon><Refresh /></el-icon>
                </el-button>
              </div>
            </div>
          </template>
          
          <div class="log-filters">
            <el-select v-model="logFilters.level" placeholder="日志级别" size="small" style="width: 100px">
              <el-option label="全部" value="" />
              <el-option label="错误" value="error" />
              <el-option label="警告" value="warn" />
              <el-option label="信息" value="info" />
              <el-option label="调试" value="debug" />
            </el-select>
            
            <el-input 
              v-model="logFilters.keyword" 
              placeholder="搜索日志" 
              size="small" 
              style="width: 150px; margin-left: 8px"
              @keyup.enter="loadSystemLogs"
            />
            
            <el-button type="primary" size="small" @click="loadSystemLogs" style="margin-left: 8px">
              搜索
            </el-button>
          </div>
          
          <div class="log-container">
            <div v-if="loadingLogs" class="log-loading">
              <el-skeleton :rows="5" animated />
            </div>
            
            <div v-else-if="systemLogs.length === 0" class="log-empty">
              <el-empty description="暂无日志" :image-size="60" />
            </div>
            
            <div v-else class="log-list">
              <div 
                v-for="log in systemLogs" 
                :key="log.id" 
                class="log-item" 
                :class="log.level"
              >
                <div class="log-header">
                  <el-tag :type="getLogLevelType(log.level)" size="small">
                    {{ log.level.toUpperCase() }}
                  </el-tag>
                  <span class="log-time">{{ formatDate(log.timestamp, 'MM-DD HH:mm:ss') }}</span>
                </div>
                <div class="log-message">{{ log.message }}</div>
                <div v-if="log.details" class="log-details">
                  <el-collapse>
                    <el-collapse-item title="详细信息">
                      <pre>{{ log.details }}</pre>
                    </el-collapse-item>
                  </el-collapse>
                </div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 数据管理 -->
    <el-row :gutter="20" style="margin-top: 20px">
      <el-col :xs="24">
        <el-card class="module-card">
          <template #header>
            <span>数据管理</span>
          </template>
          
          <el-row :gutter="20">
            <!-- 数据备份 -->
            <el-col :xs="24" :sm="12" :md="8">
              <div class="data-section">
                <h4>数据备份</h4>
                <p class="section-desc">创建系统数据备份，确保数据安全</p>
                
                <div class="backup-info">
                  <div class="info-item">
                    <span>最后备份:</span>
                    <span>{{ dataManagement.lastBackup || '从未备份' }}</span>
                  </div>
                  <div class="info-item">
                    <span>备份大小:</span>
                    <span>{{ dataManagement.backupSize || '-' }}</span>
                  </div>
                </div>
                
                <div class="section-actions">
                  <el-button type="primary" @click="createBackup" :loading="creatingBackup">
                    <el-icon><Download /></el-icon>
                    创建备份
                  </el-button>
                  <el-button @click="showBackupHistory">
                    备份历史
                  </el-button>
                </div>
              </div>
            </el-col>
            
            <!-- 数据恢复 -->
            <el-col :xs="24" :sm="12" :md="8">
              <div class="data-section">
                <h4>数据恢复</h4>
                <p class="section-desc">从备份文件恢复系统数据</p>
                
                <div class="restore-upload">
                  <el-upload
                    ref="uploadRef"
                    :auto-upload="false"
                    :show-file-list="false"
                    accept=".sql,.zip"
                    @change="handleBackupFileChange"
                  >
                    <el-button>
                      <el-icon><Upload /></el-icon>
                      选择备份文件
                    </el-button>
                  </el-upload>
                  
                  <div v-if="selectedBackupFile" class="selected-file">
                    <span>{{ selectedBackupFile.name }}</span>
                    <el-button type="text" @click="selectedBackupFile = null">
                      <el-icon><Close /></el-icon>
                    </el-button>
                  </div>
                </div>
                
                <div class="section-actions">
                  <el-button 
                    type="danger" 
                    :disabled="!selectedBackupFile"
                    @click="restoreFromBackup" 
                    :loading="restoringBackup"
                  >
                    <el-icon><Upload /></el-icon>
                    恢复数据
                  </el-button>
                </div>
              </div>
            </el-col>
            
            <!-- 数据清理 -->
            <el-col :xs="24" :sm="12" :md="8">
              <div class="data-section">
                <h4>数据清理</h4>
                <p class="section-desc">清理过期和无用的数据</p>
                
                <div class="cleanup-options">
                  <el-checkbox-group v-model="cleanupOptions">
                    <el-checkbox label="logs">清理30天前的日志</el-checkbox>
                    <el-checkbox label="sessions">清理过期会话</el-checkbox>
                    <el-checkbox label="temp">清理临时文件</el-checkbox>
                    <el-checkbox label="cache">清理缓存数据</el-checkbox>
                  </el-checkbox-group>
                </div>
                
                <div class="section-actions">
                  <el-button 
                    type="warning" 
                    :disabled="cleanupOptions.length === 0"
                    @click="cleanupData" 
                    :loading="cleaningData"
                  >
                    <el-icon><Delete /></el-icon>
                    开始清理
                  </el-button>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
    </el-row>

    <!-- 备份历史对话框 -->
    <el-dialog
      v-model="backupHistoryVisible"
      title="备份历史"
      width="800px"
    >
      <el-table :data="backupHistory" stripe>
        <el-table-column prop="filename" label="文件名" />
        <el-table-column prop="size" label="大小" width="100" />
        <el-table-column prop="createdAt" label="创建时间" width="160">
          <template #default="{ row }">
            {{ formatDate(row.createdAt, 'YYYY-MM-DD HH:mm:ss') }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button type="text" size="small" @click="downloadBackup(row)">
              下载
            </el-button>
            <el-button type="text" size="small" @click="deleteBackup(row)" class="danger">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { formatDate } from '@/utils'
import { ElMessage, ElMessageBox } from 'element-plus'
import api from '@/utils/api'
import {
  Refresh,
  Monitor,
  Coin,
  Lightning,
  FolderOpened,
  Download,
  Upload,
  Close,
  Delete
} from '@element-plus/icons-vue'

const loadingLogs = ref(false)
const savingConfig = ref(false)
const creatingBackup = ref(false)
const restoringBackup = ref(false)
const cleaningData = ref(false)
const backupHistoryVisible = ref(false)
const uploadRef = ref()
const selectedBackupFile = ref(null)

const systemStatus = reactive({
  server: {
    status: 'online',
    cpu: 45,
    memory: 68,
    uptime: '15天 8小时'
  },
  database: {
    status: 'online',
    connections: 25,
    qps: 150,
    storage: '2.3GB'
  },
  cache: {
    status: 'online',
    hitRate: 95,
    memory: '512MB',
    keys: 1250
  },
  storage: {
    status: 'online',
    total: '100GB',
    used: '45GB',
    free: '55GB'
  }
})

const systemConfig = reactive({
  systemName: '校园活动报名系统',
  systemDescription: '为校园活动提供便捷的报名和管理服务',
  allowRegistration: true,
  requireEmailVerification: true,
  maxFileSize: '10',
  sessionTimeout: '30'
})

const logFilters = reactive({
  level: '',
  keyword: ''
})

const systemLogs = ref([])
const backupHistory = ref([])
const cleanupOptions = ref([])

const dataManagement = reactive({
  lastBackup: '2024-01-15 14:30:00',
  backupSize: '1.2GB'
})

const getLogLevelType = (level) => {
  const typeMap = {
    error: 'danger',
    warn: 'warning',
    info: 'info',
    debug: 'success'
  }
  return typeMap[level] || 'info'
}

const refreshSystemInfo = async () => {
  try {
    const response = await api.get('/admin/system/status')
    const data = response.data.data
    
    Object.assign(systemStatus, data)
    ElMessage.success('系统状态已刷新')
    
  } catch (error) {
    console.error('刷新系统状态失败:', error)
    ElMessage.error('刷新系统状态失败')
  }
}

const loadSystemConfig = async () => {
  try {
    const response = await api.get('/admin/system/config')
    const data = response.data.data
    
    Object.assign(systemConfig, data)
    
  } catch (error) {
    console.error('加载系统配置失败:', error)
    ElMessage.error('加载系统配置失败')
  }
}

const saveSystemConfig = async () => {
  try {
    savingConfig.value = true
    
    await api.put('/admin/system/config', systemConfig)
    ElMessage.success('系统配置保存成功')
    
  } catch (error) {
    console.error('保存系统配置失败:', error)
    ElMessage.error('保存系统配置失败')
  } finally {
    savingConfig.value = false
  }
}

const loadSystemLogs = async () => {
  try {
    loadingLogs.value = true
    
    const params = {
      level: logFilters.level,
      keyword: logFilters.keyword,
      limit: 50
    }
    
    const response = await api.get('/admin/system/logs', { params })
    systemLogs.value = response.data.data || []
    
  } catch (error) {
    console.error('加载系统日志失败:', error)
    ElMessage.error('加载系统日志失败')
  } finally {
    loadingLogs.value = false
  }
}

const clearLogs = async () => {
  try {
    await ElMessageBox.confirm(
      '确定要清空所有系统日志吗？此操作不可恢复。',
      '确认清空',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    await api.delete('/admin/system/logs')
    ElMessage.success('日志清空成功')
    loadSystemLogs()
    
  } catch (error) {
    if (error !== 'cancel') {
      ElMessage.error('清空日志失败')
    }
  }
}

const exportLogs = async () => {
  try {
    const response = await api.get('/admin/system/logs/export', {
      params: logFilters,
      responseType: 'blob'
    })
    
    const blob = new Blob([response.data], { type: 'text/plain' })
    const url = window.URL.createObjectURL(blob)
    const link = document.createElement('a')
    link.href = url
    link.download = `系统日志_${formatDate(new Date(), 'YYYY-MM-DD')}.log`
    link.click()
    
    window.URL.revokeObjectURL(url)
    ElMessage.success('日志导出成功')
    
  } catch (error) {
    ElMessage.error('导出日志失败')
  }
}

const createBackup = async () => {
  try {
    await ElMessageBox.confirm(
      '创建备份可能需要一些时间，确定要继续吗？',
      '确认备份',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }
    )
    
    creatingBackup.value = true
    
    const response = await api.post('/admin/system/backup')
    const data = response.data.data
    
    ElMessage.success('备份创建成功')
    dataManagement.lastBackup = data.createdAt
    dataManagement.backupSize = data.size
    
  } catch (error) {
    if (error !== 'cancel') {
      ElMessage.error('创建备份失败')
    }
  } finally {
    creatingBackup.value = false
  }
}

const showBackupHistory = async () => {
  try {
    const response = await api.get('/admin/system/backup/history')
    backupHistory.value = response.data.data || []
    backupHistoryVisible.value = true
  } catch (error) {
    ElMessage.error('获取备份历史失败')
  }
}

const downloadBackup = async (backup) => {
  try {
    const response = await api.get(`/admin/system/backup/${backup.id}/download`, {
      responseType: 'blob'
    })
    
    const blob = new Blob([response.data])
    const url = window.URL.createObjectURL(blob)
    const link = document.createElement('a')
    link.href = url
    link.download = backup.filename
    link.click()
    
    window.URL.revokeObjectURL(url)
    ElMessage.success('下载成功')
    
  } catch (error) {
    ElMessage.error('下载失败')
  }
}

const deleteBackup = async (backup) => {
  try {
    await ElMessageBox.confirm(
      `确定要删除备份文件 ${backup.filename} 吗？`,
      '确认删除',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    await api.delete(`/admin/system/backup/${backup.id}`)
    ElMessage.success('删除成功')
    showBackupHistory()
    
  } catch (error) {
    if (error !== 'cancel') {
      ElMessage.error('删除失败')
    }
  }
}

const handleBackupFileChange = (file) => {
  selectedBackupFile.value = file
}

const restoreFromBackup = async () => {
  try {
    await ElMessageBox.confirm(
      '恢复数据将覆盖当前所有数据，确定要继续吗？建议先创建当前数据的备份。',
      '确认恢复',
      {
        confirmButtonText: '确定恢复',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    restoringBackup.value = true
    
    const formData = new FormData()
    formData.append('backup', selectedBackupFile.value.raw)
    
    await api.post('/admin/system/restore', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
    
    ElMessage.success('数据恢复成功')
    selectedBackupFile.value = null
    
  } catch (error) {
    if (error !== 'cancel') {
      ElMessage.error('数据恢复失败')
    }
  } finally {
    restoringBackup.value = false
  }
}

const cleanupData = async () => {
  try {
    await ElMessageBox.confirm(
      `确定要执行以下清理操作吗？\n${cleanupOptions.value.map(option => {
        const optionMap = {
          logs: '• 清理30天前的日志',
          sessions: '• 清理过期会话',
          temp: '• 清理临时文件',
          cache: '• 清理缓存数据'
        }
        return optionMap[option]
      }).join('\n')}`,
      '确认清理',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    cleaningData.value = true
    
    await api.post('/admin/system/cleanup', {
      options: cleanupOptions.value
    })
    
    ElMessage.success('数据清理完成')
    cleanupOptions.value = []
    refreshSystemInfo()
    
  } catch (error) {
    if (error !== 'cancel') {
      ElMessage.error('数据清理失败')
    }
  } finally {
    cleaningData.value = false
  }
}

onMounted(() => {
  refreshSystemInfo()
  loadSystemConfig()
  loadSystemLogs()
})
</script>

<style scoped>
.system-management {
  max-width: 1400px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  color: white;
}

.header-content {
  flex: 1;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px 0;
}

.page-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 12px;
  margin-left: 20px;
}

.status-row {
  margin-bottom: 24px;
}

.status-card {
  height: 160px;
}

.status-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.status-info {
  flex: 1;
}

.status-title {
  font-size: 14px;
  color: #909399;
  margin-bottom: 8px;
}

.status-value {
  font-size: 18px;
  font-weight: 600;
}

.status-value.online {
  color: #67c23a;
}

.status-value.offline {
  color: #f56c6c;
}

.status-icon {
  font-size: 32px;
  opacity: 0.3;
}

.status-icon.online {
  color: #67c23a;
}

.status-icon.offline {
  color: #f56c6c;
}

.status-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #606266;
}

.module-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.log-filters {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #ebeef5;
}

.log-container {
  height: 400px;
  overflow-y: auto;
}

.log-loading,
.log-empty {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-item {
  padding: 12px;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  background: #fafafa;
}

.log-item.error {
  border-color: #f56c6c;
  background: #fef0f0;
}

.log-item.warn {
  border-color: #e6a23c;
  background: #fdf6ec;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.log-time {
  font-size: 12px;
  color: #909399;
}

.log-message {
  font-size: 13px;
  color: #303133;
  line-height: 1.4;
}

.log-details {
  margin-top: 8px;
}

.log-details pre {
  font-size: 12px;
  color: #606266;
  background: #f5f7fa;
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
}

.data-section {
  padding: 16px;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  height: 100%;
}

.data-section h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  color: #303133;
}

.section-desc {
  font-size: 13px;
  color: #909399;
  margin: 0 0 16px 0;
  line-height: 1.4;
}

.backup-info {
  margin-bottom: 16px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}

.info-item span:first-child {
  color: #909399;
}

.info-item span:last-child {
  color: #303133;
  font-weight: 500;
}

.restore-upload {
  margin-bottom: 16px;
}

.selected-file {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding: 8px;
  background: #f5f7fa;
  border-radius: 4px;
  font-size: 13px;
}

.cleanup-options {
  margin-bottom: 16px;
}

.cleanup-options .el-checkbox {
  display: block;
  margin-bottom: 8px;
}

.section-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.danger {
  color: #f56c6c !important;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }
  
  .header-actions {
    margin-left: 0;
  }
  
  .status-card {
    height: auto;
    margin-bottom: 16px;
  }
  
  .log-filters {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }
  
  .log-filters .el-select,
  .log-filters .el-input {
    width: 100% !important;
    margin-left: 0 !important;
  }
  
  .data-section {
    margin-bottom: 16px;
  }
  
  .section-actions {
    flex-direction: column;
  }
  
  .section-actions .el-button {
    width: 100%;
  }
}
</style>